<%--
  Created by IntelliJ IDEA.
  User: 王韫琛
  Date: 2021/2/1
  Time: 16:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户迁出界面</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.all.js">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js">
    <style type="text/css">
        #form_body{
            margin-left: 30%;
        }
    </style>
</head>
<body>
<div style="text-align: center;">
    <br>
    <br>
    <div class="layui-inline">
        <form class="layui-form layui-form-pane" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label" for="username" style="width: 160px">用户名:</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" id="username" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入用户名" placeholder="请输入用户名" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="name" style="width: 160px">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="name" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入姓名" placeholder="请输入姓名" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="gender"style="width: 160px">性别:</label>
                <div class="layui-input-inline">
                    <input type="radio" name="gender" id="gender" value="男" title="男" checked="checked">
                    <input type="radio" name="gender" value="女" title="女">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="age" style="width: 160px">年龄:</label>
                <div class="layui-input-inline">
                    <input type="text" name="age" id="age" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入年龄" placeholder="请输入年龄" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="phone" style="width: 160px">手机号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" id="phone" class="layui-input" required lay-verify="required|phone"
                           lay-reqText="请输入正确的手机号" placeholder="请输入手机号" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="identity_card" style="width: 160px">身份证号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="identity_card" id="identity_card" class="layui-input" required lay-verify="identity"
                           lay-reqText="身份证号" placeholder="身份证号" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="proof" style="width: 160px">七日内核算证明:</label>
                <div class="layui-input-inline">
                    <input type="radio" name="proof" id="proof" value="有" title="有" checked="checked">
                    <input type="radio" name="proof" value="无" title="无">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="destination" style="width: 160px">目的地:</label>
                <div class="layui-input-inline">
                    <input type="text" name="destination" id="destination" class="layui-input" required lay-verify="required"
                           lay-reqText="请输入目的地" placeholder="请输入目的地" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="test1" style="width: 160px">添加时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="addtime" required lay-verify="required|data" class="layui-input" id="test1">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline" style="padding-left: 45px">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="layui-btn" lay-submit lay-filter="doSubmit" lay-event="add">提交</button>
                    <button type="reset" class="layui-btn layui-btn-warm">重置</button>
                </div>
            </div>

        </form>
    </div>
</div>
</div>
<%--js--%>
<script src="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js"></script>
<script>
    layui.use(['laydate','layer','form','jquery'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        var $ = layui.jquery;
        var url = "/submitInformation";
        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
            ,format: 'yyyy-MM-dd'
        });
        //标识是否存在
        var flag = false;
        $("#username").blur(function () {
            //获取输入的用户名
            let username = $(this).val().trim();
            console.log(username);
            //判断是否为空
            if(username.length>0){
                $.get("/SuperSelectByUsername",{"username":username},function (result) {
                    if (result.success){
                        layer.tips(result.message,"#username");
                        flag = false;
                    }else {
                        flag = true;
                        layer.tips(result.message,"#username");
                    }
                },"json");
            }
        });
        //判断身份证是否与用户名相符
        $("#identity_card").blur(function () {
            //获取输入的用户名
            let identity_card = $(this).val().trim();
            //判断是否为空
            if (identity_card.length>0){
                $.get("/SuperSelectByIdentity",{"identity_card":identity_card},function (result) {
                    if (result.success){
                        //layer.msg(result.message);
                        layer.tips(result.message,"#identity_card");
                        flag = false;
                    }else {
                        flag = true;
                        layer.tips(result.message,"#identity_card");
                    }
                },"json");
            }
        });
        //表单监听事件
        form.on("submit(doSubmit)", function (data) {
            if (flag){
                layer.msg("上面信息有错误");
            }else {
                $.post(url, data.field, function (result) {
                    if (result.success) {
                        layer.alert(result.message, {icon: 1},function (index) {
                            location.href="";
                            layer.close(index);
                        });
                    } else {
                        layer.alert(result.message, {icon: 2});
                    }
                }, "json");
            }
            //禁止页面跳转
            return false;
        });
    });
</script>
</body>
</html>

